package practice01;

public class Demo629 {
    public static void main(String[] args) {
        //写一个算法,大小写切换,并且如果不是字母,不用替换,这样输出
        //比如:我输入:"Hj123zF"
        //返回:"hJ123Zf"
        //String toggleString(String str)
        String str = "hiadui1BSAYU12";
        System.out.println(str);
        String sc = toggleString(str);
        System.out.println(sc);
    }
    public static String toggleString(String str){
        char[] arr = str.toCharArray();
//        for (int i=0;i<arr.length;i++){
//            if (arr[i]>='a' && arr[i]<='z'){
//                arr[i] = (char) (arr[i]-32);
//            }else if (arr[i]>='A' && arr[i]<='Z'){
//                arr[i] = (char) (arr[i]+32);
//            }
//        }
        for (int i=0;i<arr.length;i++){
            if (Character.isLowerCase(arr[i])){
                arr[i] = Character.toUpperCase(arr[i]);
            }else if (Character.isUpperCase(arr[i])){
                arr[i] = Character.toLowerCase(arr[i]);
            }
        }
        return String.valueOf(arr);
    }
}
